package com.tedu;

import java.awt.*;

/**
 * 游戏角色  忍者实体（玩家1+玩家2）
 */
public class Ninja {
    //属性
    private int x,y,w,h; //忍者的位置大小
    private Image bg;// 忍者背景图片
    private int index;// 显示哪个忍者

    //构造方法
    public Ninja(int x, int y, int w, int h, Image bg, int index) {
        this.x = x;
        this.y = y;
        this.w = w;
        this.h = h;
        this.bg = bg;
        this.index = index;
    }

    /**
     * 忍者动作+显示
     * @param graphics
     * @param dir  显示哪一个忍者
     */
    public void moveanddraw(Graphics graphics){
        //显示+移动
       switch (index)
       {
           case 1:
               //dx1: 绘制的x,dy1：绘制y
               //dx2,dy2: 绘制的右下角
               //sx1,sy1: 图片左上的点
                // sx2,sy2: 图片右下角的点  35*45
               graphics.drawImage(bg,x,y,x+w,y+h,0,0,33,44,null);
               break;
           case 2:
               graphics.drawImage(bg,x,y,x+w,y+h,33,0,70,40,null);
               break;
           case 3:
               graphics.drawImage(bg,x,y,x+w,y+h,70,0,118,36,null);
               break;
           case 4:
               graphics.drawImage(bg,x,y,x+w,y+h,118,0,170,33,null);
               break;
           case 5:
               graphics.drawImage(bg,x,y,x+w,y+h,170,0,215,36,null);
               break;
           case 6:
               graphics.drawImage(bg,x,y,x+w,y+h,215,0,270,40,null);
               break;

       }



    }

    // alt+insert
    // setget方法
    //tostring


    public Image getBg() {
        return bg;
    }

    public void setBg(Image bg) {
        this.bg = bg;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public String toString() {
        return "Ninja{" +
                "x=" + x +
                ", y=" + y +
                ", w=" + w +
                ", h=" + h +
                '}';
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getW() {
        return w;
    }

    public void setW(int w) {
        this.w = w;
    }

    public int getH() {
        return h;
    }

    public void setH(int h) {
        this.h = h;
    }
}
